﻿namespace DeltaGroup.WheelOfJeopardy.Model
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Xml.Serialization;

    using DeltaGroup.WheelOfJeopardy.ChallengeManager;

    [Serializable]
    public class Challenge : INotifyPropertyChanged
    {
        #region Fields

        private bool _isChallenged;
        private int _point;

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="Challenge"/> class.
        /// </summary>
        public Challenge()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Challenge"/> class.
        /// </summary>
        /// <param name="challenge">The challenge.</param>
        public Challenge(Challenge challenge)
            : this(challenge.Category, challenge.Point, challenge.Prompt, challenge.ExpectedResponse, challenge.SynonymList,
                challenge.ResponseOptionList)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Challenge"/> class.
        /// </summary>
        /// <param name="category">The category.</param>
        /// <param name="prompt">The prompt.</param>
        /// <param name="expectedResponse">The expected response.</param>
        /// <param name="synonyms">The synonyms.</param>
        /// <param name="responseOptions">The response options.</param>
        public Challenge(string category, int point, string prompt, string expectedResponse, List<Synonym> synonyms, List<ResponseOption> responseOptions)
        {
            this.Category = category;
            this.Point = point;
            this.Prompt = prompt;
            this.ExpectedResponse = expectedResponse;
            this.SynonymList = synonyms;
            this.ResponseOptionList = responseOptions;
        }

        #endregion Constructors

        #region Events

        /// <summary>
        /// Occurs when a property value changes.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion Events

        #region Properties

        /// <summary>
        /// Gets or sets the category.
        /// </summary>
        /// <value>The category.</value>
        [XmlAttribute]
        public string Category
        {
            get; set;
        }

        /// <summary>
        /// Gets or sets the expected response.
        /// </summary>
        /// <value>The expected response.</value>
        [XmlAttribute]
        public string ExpectedResponse
        {
            get; set;
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is challenged.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is challenged; otherwise, <c>false</c>.
        /// </value>
        public bool IsChallenged
        {
            get { return _isChallenged; }
            set
            {
                _isChallenged = value;
                FirePropertyChanged("IsChallenged");
            }
        }

        /// <summary>
        /// Gets or sets the point.
        /// </summary>
        /// <value>The point.</value>
        [XmlAttribute]
        public int Point
        {
            get { return _point; }
            set
            {
                _point = value;
                FirePropertyChanged("Point");
            }
        }

        /// <summary>
        /// Gets or sets the prompt.
        /// </summary>
        /// <value>The prompt.</value>
        [XmlAttribute]
        public string Prompt
        {
            get; set;
        }

        /// <summary>
        /// Gets or sets the response option list.
        /// </summary>
        /// <value>The response option list.</value>
        [XmlElement]
        public List<ResponseOption> ResponseOptionList
        {
            get; set;
        }

        /// <summary>
        /// Gets or sets the synonym list.
        /// </summary>
        /// <value>The synonym list.</value>
        [XmlElement]
        public List<Synonym> SynonymList
        {
            get; set;
        }

        #endregion Properties

        #region Methods

        /// <summary>
        /// Fires the property changed.
        /// </summary>
        /// <param name="name">The name.</param>
        private void FirePropertyChanged(string name)
        {
            if (PropertyChanged == null)
                return;

            PropertyChanged(this, new PropertyChangedEventArgs(name));
        }

        #endregion Methods
    }
}